
#include "scene_qt.h"

Scene_qt::Scene_qt(QWidget * parent)
    : QMainWindow{parent},
    view(null),
    scene(null)
{
    setup(); //设置界面属性及图标
    setbackbutton();//返回按钮
    view->scale(0.5,0.5);
}

Scene_qt::~Scene_qt(){
    if(view)delete view;
    if(scene) delete scene;
    view = null;
    scene = null;
}

void Scene_qt::setup()
{
    this->setFixedSize(GAME_WIDTH,GAME_HEIGHT);
    this->setWindowIcon(QIcon(":resource/img/logo.png"));
    this->setWindowTitle("");
    scene = new QGraphicsScene(this);
    view = new View_qt(scene);
    this->setCentralWidget(view);
}

void Scene_qt::setbackbutton()
{
    MyPushButton * backBtn = new MyPushButton(":/resource/img/button/BackButton.png",":/resource/img/button/BackButtonSelected.png");
    backBtn->setParent(this);
    backBtn->move(this->width()-backBtn->width(),this->height()-backBtn->height());
    connect(backBtn,&MyPushButton::clicked,this,[=]()
            {
                QTimer::singleShot(200,this,[=]()
                                   {
                                       emit this->chooseSceneBack();
                                   });
            });
}

void Scene_qt::paintEvent(QPaintEvent *)//绘制背景图片
{
    QPixmap pix;
    pix.load(":/resource/img/map.png");
    scene->addPixmap(pix);
}

void Scene_qt::closeEvent(QCloseEvent *event)
{
    QMainWindow::closeEvent(event);
    emit this->save();
}


